<?php
	include_once('class/produk.php');
	include_once('class/biodata.php');
	if(isset($_GET['cetak']))
	{
		$id_produk=$_GET['id'];
		$_SESSION['id_produk']=$id_produk;
		$id_penjual=$_SESSION['login'];
		$produk_dao=new Produk();
		$penjualan=$produk_dao->getProdukGeraiById($id_penjual,$id_produk);
		
		$biodata_dao=new Biodata();
		
		$biodata_penjual=$biodata_dao->getBiodata($id_penjual);
		
		$produk_nya=$produk_dao->getProduk($id_produk);
				
		foreach($produk_nya as $detail_produk)
		{
			$nama_produk=$detail_produk['nama'];
			$satuan_produk=$detail_produk['nama_satuan'];
			$harga_produk=$detail_produk['harga'];
		}
		
		foreach($biodata_penjual as $detail_biodata)
		{
			$nama_penjual=$detail_biodata['nama'];
			$alamat_penjual=$detail_biodata['alamat'];
			$email_penjual=$detail_biodata['email'];
			$telp_penjual=$detail_biodata['telp'];
		}
		
		//print_r($penjualan);
		
		$html="<!DOCTYPE html>
<html><head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
	<title>Print Invoice</title>
	<style>
		*
		{
			margin:0;
			padding:0;
			font-family:Arial;
			font-size:10pt;
			color:#000;
		}
		body
		{
			width:100%;
			font-family:Arial;
			font-size:10pt;
			margin:0;
			padding:0;
		}
		
		p
		{
			margin:0;
			padding:0;
		}
		
		#wrapper
		{
			width:180mm;
			margin:0 15mm;
		}
		
		.page
		{
			height:300mm;
			width:210mm;
			page-break-after:always;
		}

		table
		{
			border-left: 1px solid #ccc;
			border-top: 1px solid #ccc;
			
			border-spacing:0;
			border-collapse: collapse; 
			
		}
		
		table td 
		{
			border-right: 1px solid #ccc;
			border-bottom: 1px solid #ccc;
			padding: 2mm;
		}
		
		table.heading
		{
			height:50mm;
		}
		
		h1.heading
		{
			font-size:14pt;
			color:#000;
			font-weight:normal;
		}
		
		h2.heading
		{
			font-size:9pt;
			color:#000;
			font-weight:normal;
		}
		
		hr
		{
			color:#ccc;
			background:#ccc;
		}
		
		#invoice_body
		{
			height: 159mm;
		}
		
		#invoice_body , #invoice_total
		{	
			width:100%;
		}
		#invoice_body table , #invoice_total table
		{
			width:100%;
			border-left: 1px solid #ccc;
			border-top: 1px solid #ccc;
	
			border-spacing:0;
			border-collapse: collapse; 
			
			margin-top:5mm;
		}
		
		#invoice_body table td , #invoice_total table td
		{
			text-align:center;
			font-size:9pt;
			border-right: 1px solid #ccc;
			border-bottom: 1px solid #ccc;
			padding:2mm 0;
		}
		
		#invoice_body table td.mono  , #invoice_total table td.mono
		{
			font-family:monospace;
			text-align:right;
			padding-right:3mm;
			font-size:10pt;
		}
		
		#footer
		{	
			width:180mm;
			margin:0 15mm;
			padding-bottom:3mm;
		}
		#footer table
		{
			width:100%;
			border-left: 1px solid #ccc;
			border-top: 1px solid #ccc;
			
			background:#eee;
			
			border-spacing:0;
			border-collapse: collapse; 
		}
		#footer table td
		{
			width:25%;
			text-align:center;
			font-size:9pt;
			border-right: 1px solid #ccc;
			border-bottom: 1px solid #ccc;
		}
	</style>
</head>
<body>
	<div id=\"wrapper\">
    
    <p style=\"text-align:center; font-weight:bold; padding-top:5mm;\">Laporan Penjualan Produk</p>";
	
	$html.="<p style=\"text-align:center; font-weight:bold; padding-top:5mm;\">Nama Produk :".$nama_produk."</p>
    <br>
    <table class=\"heading\" style=\"width:100%;\">
    	<tbody><tr>
    		<td style=\"width:80mm;\">
    			<h1 class=\"heading\">".$nama_penjual."</h1>
				<h2 class=\"heading\">
					Alamat&nbsp;	:&nbsp;".$alamat_penjual."<br>
					E-mail&nbsp; : &nbsp;".$email_penjual."<br>
					Telp&nbsp; : &nbsp;".$telp_penjual."
				</h2>
			</td>
			<td rowspan=\"2\" style=\"padding:3mm;\" align=\"right\" valign=\"top\">
				<table>
					<tbody><tr><td>Invoice No : </td><td>11-12-17</td></tr>
					<tr><td>Tanggal : </td><td>".date('d-M-Y')."</td></tr>
					<tr><td>Mata Uang : </td><td>Rupiah</td></tr>
				</tbody></table>
			</td>
		</tr>
    </tbody></table>
		
		
	<div id=\"content\">
		
		<div id=\"invoice_body\">
			<table>
			<tbody><tr style=\"background:#eee;\">
				<td style=\"width:8%;\"><b>Sl. No.</b></td>
				<td><b>Pembeli</b></td>
				<td style=\"width:10%;\"><b>Tgl Beli</b></td>
				<td style=\"width:10%;\"><b>Quantity</b></td>
				<td style=\"width:10%;\"><b>Harga Satuan</b></td>
				<td style=\"width:10%;\"><b>Total</b></td>
			</tr>
			</tbody></table>
			
			<table>
			<tbody>";
			$i=1;
			$total=0;
			foreach($penjualan as $det_jual)
			{

			$html.="<tr>
			    <td style=\"width:8%;\">".$i."</td>
			    <td style=\"text-align:left; padding-left:10px;\">Nama :".$det_jual['nama_pembeli']."<br>Email :".$det_jual['email_pembeli']."<br>Telp :".$det_jual['telp_pembeli']."</td>
			    <td class=\"mono\" style=\"width:15%;\">".$det_jual['tgl_beli']."</td>
				<td style=\"width:10%;\" class=\"mono\">".$det_jual['jumlah']."</td>
			    <td style=\"width:10%;\" class=\"mono\">".$det_jual['harga']."</td>
				<td style=\"width:10%;\" class=\"mono\">".$det_jual['jumlah']*$det_jual['harga']."</td>
			</tr>";
				$harga=$det_jual['jumlah']*$det_jual['harga'];
				$total+=$harga;
				$i++;
			}

			$html.="<tr>
				<td colspan=\"4\"></td>
				<td></td>
				<td></td>
			</tr>
			
			<tr>
				<td colspan=\"4\"></td>
				<td>Total :</td>
				<td class=\"mono\">".$total."</td>
			</tr>
		</tbody></table>
		</div>
		<br>
		<hr>
		<br>
		
		<table style=\"width:100%; height:35mm;\">
			<tbody><tr>
				<td style=\"width:65%;\" valign=\"top\">
					Informasi :<br>
					Laporan ini adalah laporan penjualan dari : <br>
					<b>".$nama_penjual."</b>
					<br><br>
					Semua Transaksi Yang Terjadi Harap Dilakukan Pengecekan<br><br>
				</td>
				<td>
				<div id=\"box\">
					Authorised Reseller of Sayco
				</div>
				</td>
			</tr>
		</tbody></table>
	</div>
	
	<br>
	
	</div>
	
	<htmlpagefooter name=\"footer\">
		<hr>
		<div id=\"footer\">	
			<table>
				<tbody><tr><td>Generate From Sayco Corporation</td></tr>
			</tbody></table>
		</div>
	</htmlpagefooter>
	<sethtmlpagefooter name=\"footer\" value=\"on\">
	

</sethtmlpagefooter></body></html>";
			
		
		
		$myFile = "invoice.html";
		$fh = fopen($myFile, 'w') or die("can't open file");
		fwrite($fh, $html);
		fclose($fh);
		
		header('Location:invoice.php');
		//include_once('/invoice.php');
			
	}
?>